package com.zrwl.poscloud.commons.config.file;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;


@RefreshScope
@Configuration
@Data
public class FileConfig {

    //客户端存储文件地址
    @Value(value = "${filePath.clientBackstageDownloadFileStorePath}")
    String clientBackstageDownloadFileStorePath;

    //扫描树结根目录
    @Value(value = "${filePath.rootPath}")
    String rootPath;

    public boolean sync(int type) {
        switch (type) {
            case 1:
                return false;
            case 2:
                return false;
            case 3:
                return false;
            case 4:
                return false;
            case 5:
                return false;
            case 6:
                return false;
            case 7:
                return false;
            case 8:
                return false;
            case 9:
                return false;
            case 10:
                return false;
            case 99:
                return false;
        }
        return false;
    }

    //文件路径不带根目录，相对存储位置
    public String filePath(String ownerCode, int type) {
        return getPath(ownerCode, type);
    }
    String getPath(String ownerCode, int type) {
        switch (type) {
            case 1:
                return FileTypeEnums.rootFile.filePath;
            case 2:
                return FileTypeEnums.softwareUpdate.filePath;
            case 3:
                return FileTypeEnums.systemContentManage.filePath;
            case 4:
                return FileTypeEnums.businessProductPic.filePath;
            case 5:
                return FileTypeEnums.baseAndCover.filePath;
            case 6:
                return ("/" + ownerCode + FileTypeEnums.merchantProductPic.filePath);
            case 7:
                return FileTypeEnums.databaseBackup.filePath;
            case 8:
                return FileTypeEnums.gateUpdate.filePath;
            case 9:
                return FileTypeEnums.posUpdate.filePath;
            case 10:
                return FileTypeEnums.userHeadPic.filePath;
            case 11:
                return FileTypeEnums.employeeFace.filePath;
            case 12:
                return FileTypeEnums.contentFrontCover.filePath;
            case 13:
                return FileTypeEnums.financialPayment.filePath;
            case 14:
                return FileTypeEnums.contentImage.filePath;
            case 15:
                return FileTypeEnums.QrCodeImage.filePath;
            case 99:
                return FileTypeEnums.others.filePath;
            default:
                return "/";
        }
    }

    //文件路径加上根目录
    public String fullFilePath(String ownerCode, int type) {
        String fileStorePath = rootPath;
        return fileStorePath + getPath(ownerCode, type);
    }

    public enum FileTypeEnums {

        rootFile(1, "根目录文件", "/"),
        softwareUpdate(2, "软件更新相关", "/systemFile/softwareUpdate"),
        systemContentManage(3, "系统发布的内容管理", "/systemFile/systemContentManage"),
        businessProductPic(4, "商务产品的图片", "/systemFile/businessProductPic"),
        baseAndCover(5, "基本信息封面等", "/systemFile/Synchronize/baseAndCover"),
        merchantProductPic(6, "商户商品图片", "/systemFile/Synchronize/companyFile/merchantProductPic"),
        databaseBackup(7, "数据库备份", "/systemFile/Synchronize/merchantFile/databaseBackup"),
        gateUpdate(8, "网关更新", "/systemFile/Synchronize/gateUpdate"),
        posUpdate(9, "POS机更新文件", "/systemFile/Synchronize/posUpdate"),
        userHeadPic(10, "用户头像", "/userFile/head"),
        employeeFace(11, "持卡人脸", "/systemFile/Synchronize/companyFile/employeeFace"),
        contentFrontCover(12, "内容封面", "/systemFile/Synchronize/companyFile/content/frontCover"),
        financialPayment(13, "财务支付", "/systemFile/Synchronize/companyFile/financialPayment/image"),
        contentImage(14, "内容图片", "/systemFile/Synchronize/companyFile/content/image"),
        QrCodeImage(15, "二维码图片", "/systemFile/Synchronize/companyFile/qrCode/image"),
        others(99, "其他", "/others"),
        tempChunk(100, "分片上传的临时文件", "/tempForChunk");

        private int fileType;
        private String fileTypeSummary;
        public String filePath;
        int packType;//0 不分包，1 按年，2按月，3按日，4按小时
//        int packCount;//每个包里面的文件个数 0不限，n是具体个数
//        int maxSize;//每个包里的最大文件空间 0 不限，n是MB大小

        FileTypeEnums(int fileType, String fileTypeSummary, String filePath) {
            this.fileType = fileType;
            this.fileTypeSummary = fileTypeSummary;
            this.filePath = filePath;
        }
    }

    public enum FileStatusEnums {

        deleted(0, "数据库标记为已删除"),
        normal(1, "正常"),
        diskDeleted(2, "磁盘已删除"),
        uploading(3, "正在上传");

        public int status;
        private String summary;

        FileStatusEnums(int status, String summary) {
            this.status = status;
            this.summary = summary;
        }
    }

}
